package seed_partner_admin

import (
	"fmt"
	"gitee.com/theegg/go-brick/app/model/partner/partner_admin/partner_admin_roles"
	"gitee.com/theegg/go-brick/app/service/app"
	"time"
)

// 管理后台角色 seed
func InitPartnerAdminRoleSeed() {

	items := make(map[int]partner_admin_roles.PartnerAdminRoles)

	items[1] = partner_admin_roles.PartnerAdminRoles{
		Id:   1,
		Pid:  0,
		Rid:  "1",
		Name: "超级管理员",

		AddUserId: 0,
		AddUserIp: "127.0.0.1",

		Mark:      "",
		Status:    1,
		CreatedAt: time.Now(),
	}

	items[2] = partner_admin_roles.PartnerAdminRoles{
		Id:   2,
		Pid:  1,
		Rid:  "1|2",
		Name: "运营经理",

		AddUserId: 0,
		AddUserIp: "127.0.0.1",

		Mark:      "",
		Status:    1,
		CreatedAt: time.Now(),
	}

	items[3] = partner_admin_roles.PartnerAdminRoles{
		Id:   3,
		Pid:  2,
		Rid:  "1|2|3",
		Name: "运营主管",

		AddUserId: 0,
		AddUserIp: "127.0.0.1",

		Mark:      "",
		Status:    1,
		CreatedAt: time.Now(),
	}

	items[4] = partner_admin_roles.PartnerAdminRoles{
		Id:   4,
		Pid:  3,
		Rid:  "1|2|3|4",
		Name: "运营专员",

		AddUserId: 0,
		AddUserIp: "127.0.0.1",

		Mark:      "",
		Status:    1,
		CreatedAt: time.Now(),
	}

	items[5] = partner_admin_roles.PartnerAdminRoles{
		Id:   5,
		Pid:  1,
		Rid:  "1|5",
		Name: "市场经理",

		AddUserId: 0,
		AddUserIp: "127.0.0.1",

		Mark:      "",
		Status:    1,
		CreatedAt: time.Now(),
	}

	items[6] = partner_admin_roles.PartnerAdminRoles{
		Id:   6,
		Pid:  5,
		Rid:  "1|5|6",
		Name: "市场主管",

		AddUserId: 0,
		AddUserIp: "127.0.0.1",

		Mark:      "",
		Status:    1,
		CreatedAt: time.Now(),
	}

	items[7] = partner_admin_roles.PartnerAdminRoles{
		Id:   7,
		Pid:  6,
		Rid:  "1|5|6|7",
		Name: "市场专员",

		AddUserId: 0,
		AddUserIp: "127.0.0.1",

		Mark:      "",
		Status:    1,
		CreatedAt: time.Now(),
	}

	count := 0
	errCount := 0
	for _, item := range items {
		_, err := app.Db().Insert(item)
		if err != nil {
			fmt.Println(err.Error())
			errCount++
		} else {
			count++
		}
	}

	fmt.Printf("%5s|%25s|%10d|%8d|\n", "", "partner_admin_roles", count, errCount)
}
